<template>
  <div class="common-layout">
    <el-container>
      <el-container>
        <el-aside width="200px"><NavMenu></NavMenu></el-aside>
        <el-container>
          <el-header height="60px"><Header></Header></el-header>
          <el-main>
            <el-card class="box-card" shadow="hover">
              <template #header>
                <div class="card-header">
                  <span>报备人员信息</span>
                </div>
              </template>
              <!--工具栏-->
              <div class="tool-nav">
                <el-input placeholder="搜索" v-model="searchStr" class="search" >
                  <template #prepend>
                    <el-select v-model="select" placeholder="Select" style="width: 120px">
                      <el-option label="姓名" value="name"/>
                      <el-option label="出发日期" value="departure_date" />
                      <el-option label="到达日期" value="arrival_date" />
                      <el-option label="返前居住地" value="before_place" />
                      <el-option label="详细地址" value="detailed_address" />
                      <el-option label="到返轨迹" value="track" />
                      <el-option label="交通方式" value="vehicle" />
                    </el-select>
                  </template>
                </el-input>
                <el-button @click="fuzzySearch">
                  <el-icon class="icon-button"><Search /></el-icon>
                  <p>搜索</p>
                </el-button>
                <el-button @click="all">
                  <el-icon class="icon-button"><refresh-right /></el-icon>
                  <p>全部</p>
                </el-button>
                <el-button
                  style="width: 120px;"
                  type="primary"
                  @click="addFiling">
                  <el-icon class="icon-button"><plus /></el-icon>
                  <p>添加报备人员</p>
                </el-button>
              </div>
              <!--工具栏-->
              <!--数据-->
              <el-table :data="tableData" style="width: 100%" height="350" v-loading="loading">
                <el-table-column type="expand">
                  <template #default="props">
                    <el-row  class="row-style">
                      <el-col :span="6">
                        <p >姓名: {{ props.row.name }}</p>
                        <p >身份证: {{ props.row.idCard }}</p>
                        <p >性别: {{ props.row.sex }}</p>
                        <p >电话: {{ props.row.telephone }}</p>                        
                      </el-col>
                      <el-col :span="6">
                        <p >出发日期: {{ props.row.departureDate }}</p>
                        <p >达到日期: {{ props.row.arrivalDate }}</p>
                        <p >返前居住地: {{ props.row.beforePlace }}</p>
                        <p >详细地址: {{ props.row.detailedAddress }}</p>
                      </el-col>
                      <el-col :span="6">
                        <p >交通方式: {{ props.row.vehicle }}</p>
                        <p >到返轨迹: {{ props.row.track }}</p>
                        <p >创建时间: {{ props.row.createTime }}</p>
                        <p >更新时间: {{ props.row.updateTime }}</p>
                      </el-col>
                    </el-row>
                  </template>
                </el-table-column>
                <el-table-column label="姓名" prop="name" width="85"/>
                <el-table-column label="性别" prop="sex" width="70"/>
                <el-table-column label="电话" prop="telephone" width="130"/>
                <el-table-column label="交通方式" prop="vehicle" width="100"/>
                <el-table-column label="返前居住地" prop="beforePlace" />
                <el-table-column label="操作" width="120">
                  <template #default="scope">
                    <el-button
                      type="primary"
                      size="small"
                      style="width:30px"
                      @click="handleEdit(scope.$index)">
                      <el-icon><edit /></el-icon>
                    </el-button>
                    <el-button
                      type="danger"
                      size="small"
                      style="width:30px"
                      @click="myconfirm(scope.$index,scope.row)">
                      <el-icon><Delete /></el-icon>
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!--数据-->
              <!--分页-->
              <div class="pagination">
                <el-pagination
                  :page-sizes="[5, 10]"
                  :background="background"
                  layout="prev, pager, next"
                  :total="total"
                  :page-size="pageSize"
                  :current-page="pageNO"
                  @current-change="handleCurrentChange"
                />
                </div>
              <!--分页-->
            </el-card>
          </el-main>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import NavMenu from '@/components/NavMenu.vue'
import Header from '@/components/Header.vue'

export default {
  name: 'HomeView',
  components: {
    NavMenu,
    Header,

  },
  data() {
    return {
      tableData: [],
      searchStr:'',
      select:'name',
      total:0,
      pageSize:7,
      pageNO:1,
      loading:true
    }
  },
  methods: {
    //跳转添加报备人员页面
    addFiling(){
      this.$router.push({
          name: "filingadd",
      });
    },
    //加载全部报备人员信息
    loadFilingInfo(){
      var that=this;
      let params = {
        pageNO:this.pageNO,
        pageSize:this.pageSize
      };
      this.axios
      .post("/filing/filinglist", params)
      .then(function (response) {
      console.log(response);
        that.tableData=response.data.rows;
        that.total=parseInt(response.data.total);
        that.loading=false;
      })
      .catch(function (error) {
        console.log(error);
      });

    },
    //换页 (全部/查询)
    handleCurrentChange(pageNO){
      this.loading=true;
      if(this.searchStr==""){
        this.pageNO=pageNO;
        this.loadFilingInfo();
      }
      else{
        this.pageNO=pageNO;
        this.fuzzySearch();
      }
    },
    //跳转编辑报备人员信息页面
    handleEdit(index) {
      this.$router.push({
          name:'filingedit',
          params:{
            data:JSON.stringify(this.tableData[index]),
          }
      })
    },
    myconfirm (index,row) {
        if(confirm('确定要删除吗')==true){
          this.handleDelete(index,row)
        }
      },
    //删除报备人员信息
    handleDelete(index,row) {
     var that=this;
     this.loading=true;
     this.axios
       .get("/filing/filingdel/"+row.id)
       .then(function () {
         that.loadFilingInfo();
       })
       .catch(function (error) {
           console.log(error);
       });
    },
    //模糊查询
    fuzzySearch(){
   this.loading=true;
      var that=this;
      let params = {
        pageNO:this.pageNO,
        pageSize:this.pageSize,
        searchStr:this.searchStr,
        select:this.select
      };
      this.axios
      .post("/filing/filingfuzzysearch", params)
      .then(function (response) {
        console.log(response);
        that.tableData=response.data.rows;
        that.total=parseInt(response.data.total);
        that.loading=false;
      })
      .catch(function (error) {
        console.log(error);
      });
    },
    //显示全部信息，并清空搜索框
    all(){
      this.loading=true;
      this.loadFilingInfo();
      this.searchStr="";
    },
  },
  mounted(){
   this.loadFilingInfo();
  }

}
</script>

<style scoped>
:deep(.el-header) { 
  padding: 0;
}
.box-card{
  height: 500px;
}
.card-header{
    float: left;
    line-height: 0px;
    color: var(--el-text-color-regular);
}
.tool-nav{
  display: flex;
  justify-content: left;
  margin-bottom: 20px;
}
.search{
  width: 300px;
  float: left;
  margin-right: 12px;
}
.icon-button{
  margin-right: 5px;
}

el-button, p{
  font-size: 13px;
}
.row-style{
  display: flex;
  justify-content: space-around;
}

.el-pagination{   
    justify-content: center;
}
.pagination{
  position: fixed;
  bottom: 25px;
  height: 40px;
  width: 940px;
  text-align: center;
}
</style>
